<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
set_time_limit(0);
$intSuppleID = intval($_data["SuppleID"]);
$intBT = intval($_data["Bet_Type"]);
$intGID = intval($_data["GambleID"]);
$flOdds = floatval($_data["Odds"]);
$flOdds2 = floatval($_data["Odds2"]);
$flStakMoney = floatval($_data["StakeMoney"]);
$isSpecial = trim($_data["isSpecial"]);
$intMemID = intval($_data["MemID"]);
$strSerialNo = trim($_data["SerialNo"]);
$intSpecialNumType = intval($_data["SpecialNumType"]);
$intOddsID = intval($_data["OddsID"]);
$intOddsID2 = intval($_data["OddsID2"]);

if($intSpecialNumType == 2 && ($intBT == 1 || $intBT == 28))$intBT = 28;

//檢驗傳入資料
if($intBT < 1 || $intGID < 1 || $intLottoID < 1 || $flOdds <= 0 || $flStakMoney <= 0 || $intMemID <= 0 || $strSerialNo == "" || (($intBT == 8 || $intBT == 10) && $flOdds2 <= 0)){
	$GLOBALS["errormessage"] = "Data Error!!";
	$GLOBALS["errorhidden"] = "\nBetType:".$intBT."\nGambleID:".$intGID."\nLottoID:".$intLottoID."\nflOdds:".$flOdds."\nStakeMoney:".$flStakMoney."\nMemID:".$intMemID."\nSerialNo:".$strSerialNo."\nLine:".__LINE__."\nPage:".__FILE__;
	AddData_Log($_SESSION["Admin_Info"] -> ID,"階層補貨下注參數錯誤 ", print_r($_data, true));
	$arrResult["isWager"] = true;
	$arrResult["WagerCon"] = "Data Error!!";
	return;
}

$strChoiceNumber = "";
$strOddsID = $intOddsID;
$strOddsID2 = $intOddsID2;
switch($intBT){
	case 7:
	case 8:
	case 9:
	case 10:
	case 11:
		$arrNum = explode(",", $_data["Number"]);
		$arrN = array();
		foreach($arrNum as $intNum){
			$arrN[(int)$intNum] = (int)$intNum;
		}
		$strNumber = implode(",", $arrN);
		break;
	
	case 31:
		include(__Common_Path."/todaygame/TodayGame".$intLottoID."_".$intBT.".inc.php");
		$arrN = array();
		$arrOddsID = array();
		$flTmpOdds = 9999999;
		$strNumber = "0";
		for($intI = 1; $intI <= 5; $intI++){
			$intNum = (int)$_data["JNNum".$intI];
			$arrN[$intNum] = $intNum;
			/*if(round($_arrTodayGame[$intGID][$intBT][$intNum]["Odds"]*1000) < $flTmpOdds){
				$flTmpOdds = round($_arrTodayGame[$intGID][$intBT][$intNum]["Odds"]*1000);
				$strNumber = $intNum;
			}elseif(round($_arrTodayGame[$intGID][$intBT][$intNum]["Odds"]*1000) == $flTmpOdds && $strNumber > $intNum){
				$strNumber = $intNum;
			}*/
			$arrOddsID[$intNum] = $intNum.":".$_arrTodayGame[$intGID][$intBT][$intNum]["OddsID"];
		}
		$strChoiceNumber = implode("|", $arrN);
		$strOddsID = implode(",", $arrOddsID);
		break;

	case 32:
	case 33:
	case 34:
	case 35:
	case 36:
	case 37:
	case 38:
	case 39:
	case 40:
	case 41:
	case 42:
	case 43:
		include(__Common_Path."/todaygame/TodayGame".$intLottoID."_".$intBT.".inc.php");

		if($intBT < 38){
			$arrNum = array(1, 12);
		}else{
			$arrNum = array(0, 9);
		}

		$arrN = array();
		$arrOddsID = array();
		$flTmpOdds = 9999999;
		$strNumber = "0";
		for($intI = $arrNum[0]; $intI <= $arrNum[1]; $intI++){
			if($_data["JNNum".$intI] == "")continue;

			$intNum = (int)$_data["JNNum".$intI];
			$arrN[$intNum] = $intNum;
			/*if(round($_arrTodayGame[$intGID][$intBT][$intNum]["Odds"]*1000) < $flTmpOdds){
				$flTmpOdds = round($_arrTodayGame[$intGID][$intBT][$intNum]["Odds"]*1000);
				$strNumber = $intNum;
			}elseif(round($_arrTodayGame[$intGID][$intBT][$intNum]["Odds"]*1000) == $flTmpOdds && $strNumber > $intNum){
				$strNumber = $intNum;
			}*/
			$arrOddsID[$intNum] = $intNum.":".$_arrTodayGame[$intGID][$intBT][$intNum]["OddsID"];
		}
		$strChoiceNumber = implode("|", $arrN);
		$strOddsID = implode(",", $arrOddsID);
		break;

	default:
		$strNumber = $_data["Number"];
		break;
}
$arrCheckKey = explode(" ", microtime());
$arrResult = RealSuppleWager($intLottoID, $intLType, $intGID, $intBT, $strNumber, $flStakMoney, $strOddsID, $flOdds, $strOddsID2, $flOdds2, $strChoiceNumber, $arrCheckKey[0],  $arrCheckKey[1]+1);

if($arrResult["isWager"] == false){
	$GLOBALS["errormessage"] = $arrResult["WagerCon"];
	AddData_Log($_SESSION["Admin_Info"] -> ID,"階層補貨下注失敗 ", "Error:".$arrResult["WagerCon"]."\n".print_r($_data, true));
	//ErrMsgOutputHTML("Error2", "", 1);
}else{
	AddData_Log($_SESSION["Admin_Info"] -> ID,"階層補貨下注成功 ", print_r($_data, true));
}
?>